#ifndef MANDELBROTWIDGET_H
#define MANDELBROTWIDGET_H

#include <memory>

#include <QWidget>
#include <QPoint>
#include <QThread>
#include <QList>

#include "mandelbrotcalculator.h"

class QResizeEvent;


class MandelbrotWidget : public QWidget
{
	Q_OBJECT
public:
	explicit MandelbrotWidget(QWidget *parent = 0);
	~MandelbrotWidget();

public slots:
	void processJobResults(QList<JobResult> jobResults);

signals:
	void requestPicture(QSize areaSize, QPointF moveOffset, double scaleFactor, int iterationMax);

protected:
	void paintEvent(QPaintEvent *) override;
	void resizeEvent(QResizeEvent * event) override;
	void wheelEvent(QWheelEvent * event) override;
	void mousePressEvent(QMouseEvent * event) override;
	void mouseMoveEvent(QMouseEvent * event) override;

private:
	QRgb generateColorFromIteration(int iteration);

private:
	MandelbrotCalculator mMandelbrotCalculator;
	QThread mThreadCalculator;
	double mScaleFactor;
	QPoint mLastMouseMovePosition;
	QPointF mMoveOffset;
	QSize mAreaSize;
	int mIterationMax;
	std::unique_ptr<QImage> mImage;
};

#endif // MANDELBROTWIDGET_H
